using MicroMsg.Common.Event;
using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Plugin.Sns.Scene;
using MicroMsg.Resource.@string;
using MicroMsg.Storage;
using MicroMsg.UI.UserContrl;
using MicroMsg.UI.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
namespace MicroMsg.UI.Page
{
	public class SnsSetOutGroupPage : BasePage
	{
		private const string TAG = "SnsSetOutGroupPage";
		private const int cNPageArgCnt = 0;
		private EventWatcher mWatchSnsGroupOp;
		private object mObjectWatcher = new object();
		private SnsTagInfo mOutGroup;
		private bool mBIsModifyingMember;
		internal Grid LayoutRoot;
		internal ModGroupMemberCtrl ctrlMemList;
		private bool _contentLoaded;
		public SnsSetOutGroupPage()
		{
			this.InitializeComponent();
			base.add_Loaded(new RoutedEventHandler(this.Page_Loaded));
			base.add_Unloaded(new RoutedEventHandler(this.Page_Unloaded));
		}
		private void Page_Loaded(object sender, RoutedEventArgs e)
		{
			Log.smethod_5("SnsSetOutGroupPage", "Page_Loaded");
		}
		private void Page_Unloaded(object sender, RoutedEventArgs e)
		{
			Log.smethod_5("SnsSetOutGroupPage", "Page_Unloaded");
		}
		protected override void OnPageIn(object[] object_0)
		{
			Log.smethod_5("SnsSetOutGroupPage", "OnPageIn");
			this.initUI();
		}
		protected override void OnPageOut()
		{
			Log.smethod_5("SnsSetOutGroupPage", "OnPageOut");
			this.unRegisterEvent();
		}
		protected override void OnPageBack()
		{
			Log.smethod_5("SnsSetOutGroupPage", "OnPageBack");
		}
		private void registerEvent()
		{
			if (this.mWatchSnsGroupOp == null)
			{
				this.mWatchSnsGroupOp = new EventWatcher(this.mObjectWatcher, null, new EventHandlerDelegate(this.OnSnsGroupOp));
				EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_SNS_TAG_MEMBER_OP_SUCCESS, this.mWatchSnsGroupOp);
				EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_SNS_TAG_MEMBER_OP_ERR, this.mWatchSnsGroupOp);
			}
		}
		private void unRegisterEvent()
		{
			if (this.mWatchSnsGroupOp != null)
			{
				EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_SNS_TAG_MEMBER_OP_SUCCESS, this.mWatchSnsGroupOp);
				EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_SNS_TAG_MEMBER_OP_ERR, this.mWatchSnsGroupOp);
				this.mWatchSnsGroupOp = null;
			}
		}
		private void OnSnsGroupOp(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			if (!this.mBIsModifyingMember || evtArgs == null || evtArgs.mObject == null)
			{
				return;
			}
			ulong num = (ulong)evtArgs.mObject;
			if (this.mOutGroup != null && num != this.mOutGroup.nTagID)
			{
				return;
			}
			base.get_Dispatcher().BeginInvoke(delegate
			{
				this.releaseCover();
			});
			switch (evtArgs.mEventID)
			{
			case EventConst.ON_NETSCENE_SNS_TAG_MEMBER_OP_SUCCESS:
				this.mBIsModifyingMember = false;
				BasePage.ShowToastInNextTopPage(strings.WCGroup_Modify_Group_Success);
				base.GoBack();
				return;
			case EventConst.ON_NETSCENE_SNS_TAG_MEMBER_OP_ERR:
			{
				this.mBIsModifyingMember = false;
				MMMessageBox mMMessageBox = MMMessageBox.Show(strings.WCGroup_Modify_Group_Fail, true, "确定");
				mMMessageBox.ReturnEvent = new DlgReturnEvent(this.OnFailedHandler);
				return;
			}
			default:
				return;
			}
		}
		private void OnFailedHandler(DlgReturnEventArg dlgReturnEventArg_0)
		{
			base.GoBack();
		}
		private void initUI()
		{
			this.mOutGroup = StorageMgr.snsTag.method_1(4uL.ToString("X16"));
			List<string> usersFromGroup = SnsGroupMgr.GetUsersFromGroup(this.mOutGroup);
			this.ctrlMemList.mMemberList = usersFromGroup;
		}
		private void releaseCover()
		{
			ProcessingCover.releaseProgressBar(this.LayoutRoot);
		}
		private void getCover(string strToShow = "  ")
		{
			ProcessingCover.getProgressBar(this.LayoutRoot, strToShow, null, false, false, null);
		}
		protected override void OnBackKeyPress(CancelEventArgs cancelEventArgs_0)
		{
			if (this.mOutGroup != null && this.isNameListChange())
			{
				cancelEventArgs_0.set_Cancel(true);
				if (!this.mBIsModifyingMember)
				{
					this.doModifyOutGroup();
				}
			}
		}
		private void doModifyOutGroup()
		{
			if (this.mBIsModifyingMember)
			{
				return;
			}
			this.getCover("  ");
			this.mBIsModifyingMember = true;
			this.registerEvent();
			NetSceneSnsTagMemberOption.Instance.doScene(SnsTagMemOptionOpCode.MM_SNS_TAG_MEM_MOD, this.mOutGroup.nTagID, this.mOutGroup.strTagName, this.ctrlMemList.GetNameList());
		}
		private bool isNameListChange()
		{
			List<string> usersFromGroup = SnsGroupMgr.GetUsersFromGroup(this.mOutGroup);
			List<string> nameList = this.ctrlMemList.GetNameList();
			int num = (usersFromGroup == null) ? 0 : usersFromGroup.get_Count();
			int num2 = (nameList == null) ? 0 : nameList.get_Count();
			if (num != num2)
			{
				return true;
			}
			if (num2 == 0)
			{
				return false;
			}
			bool result;
			using (List<string>.Enumerator enumerator = usersFromGroup.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					string current = enumerator.get_Current();
					if (!nameList.Contains(current))
					{
						result = true;
						return result;
					}
				}
				return false;
			}
			return result;
		}
		public static void GotoThisPage()
		{
			ToolFunction.GotoPageForUserControl("/Source/Plugin/Sns/Common/UI/SnsGroup/SnsSetOutGroupPage.xaml", null, false);
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/Plugin/Sns/Common/UI/SnsGroup/SnsSetOutGroupPage.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.ctrlMemList = (ModGroupMemberCtrl)base.FindName("ctrlMemList");
		}
	}
}
